package com.hdax.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdax.entity.CusDrive;
import com.hdax.entity.CusIntention;
import com.hdax.entity.CusOpportunity;
import com.hdax.service.CusOpportunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.nio.cs.SingleByte;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 商机表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/cusOpportunity")
public class CusOpportunityController {

    @Autowired
    private CusOpportunityService cusOpportunityService;

    @GetMapping("/toCusOpportunity")
    public ModelAndView toCusOpportunity(){
        return new ModelAndView("opportunity/cus_opportunity");
    }

    @PostMapping("/findCusOpportunity")
    public IPage<CusOpportunity> findCusOpportunity(Integer page,Integer limit){
        IPage<CusOpportunity> iPage = new Page<>(page,limit);
        IPage<CusOpportunity> cusOpportunity = cusOpportunityService.findCusOpportunity(iPage, new HashMap());
        return cusOpportunity;
    }


    @PostMapping("/findCusOpportunityConditional")
    public IPage<CusOpportunity> findCusOpportunityConditional(@RequestBody Map map){
        IPage<CusOpportunity> iPage = new Page<>(Long.parseLong(map.get("page").toString()),Long.parseLong(map.get("limit").toString()));
        IPage<CusOpportunity> cusOpportunity = cusOpportunityService.findCusOpportunity(iPage,map);
        return cusOpportunity;
    }

    @GetMapping("/toCusOpportunityPage")
    public ModelAndView toCusOpportunityPage(Integer id){
        ModelAndView modelAndView = new ModelAndView("opportunity/cus_opportunity_page");
        CusOpportunity cusOpportunity = cusOpportunityService.findCusOpportunityById(id);
        modelAndView.addObject("cusOpportunity",cusOpportunity);
        return modelAndView;
    }


    @PostMapping("/updateCusOpportunity")
    public String updateCusOpportunity(CusOpportunity cusOpportunity){
        cusOpportunity.setUpdateTime(LocalDateTime.now());
        cusOpportunityService.updateById(cusOpportunity);
        return "success";
    }

}

